#pragma once

#include <iostream>
#include <cstdarg>
#include <cstring>
#include <ctime>

using namespace std;

#define NORMAL 0
#define DEBUG 1
#define WARNING 2
#define ERROR 5
#define FATAL 4

#define NUM 1024

const char *tolevelstr(int level)
{
    switch (level)
    {
    case NORMAL:
        return "NORMAL";
    case DEBUG:
        return "DEBUG";
    case WARNING:
        return "WARNING";
    case ERROR:
        return "ERROR";
    case FATAL:
        return "FATAL";
    default:
        return nullptr;
    }
}

void logMessage(int level, const char *format, ...)
{
    va_list arg;
    va_start(arg, format);

    char logcontent[NUM];
    vsnprintf(logcontent, sizeof(logcontent), format, arg);

    char logprefix[NUM];

    time_t rawtime;
    struct tm *info;

    time(&rawtime);

    info = localtime(&rawtime);
    char *tmp = asctime(info);
    tmp[strlen(tmp) - 1] = 0;
    snprintf(logprefix, sizeof(logprefix), "[%s][%s]", tolevelstr(level), tmp);

    cout << logprefix << " " << logcontent << endl;

}